package com.ocean.admin.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ocean.admin.core.annotation.Log;
import com.ocean.admin.core.annotation.enums.BusinessType;
import com.ocean.admin.entity.SysPost;
import com.ocean.admin.model.dto.post.SysPostQueryDTO;
import com.ocean.admin.model.dto.post.SysPostSaveDTO;
import com.ocean.admin.model.dto.post.SysPostUpdateDTO;
import com.ocean.admin.model.vo.post.SysPostVo;
import com.ocean.admin.service.ISysPostService;
import com.ocean.core.util.response.ResultSet;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 岗位信息表 前端控制器
 * </p>
 *
 * @author zhang
 * @since 2022-08-16
 */
@Tag(name = "岗位管理")
@RestController
@RequestMapping("/admin/sys-post")
public class SysPostController {

    @Autowired
    private ISysPostService iSysPostService;

    /**
     * 分页查询岗位列表
     *
     * @param queryDTO 查询条件
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermission('system:post:pageList')")
    @Operation(summary = "分页查询岗位列表")
    @PostMapping(value = "pageList")
    public ResultSet<IPage<SysPostVo>> pageList(@Validated @RequestBody SysPostQueryDTO queryDTO) {
        return ResultSet.ok(iSysPostService.pageList(queryDTO));
    }

    /**
     * 岗位列表查询
     *
     * @return 结果
     */
    @Operation(summary = "岗位列表查询")
    @PreAuthorize("@ss.hasPermission('system:post:postList')")
    @GetMapping(value = "postList")
    public ResultSet<List<SysPost>> postList() {
        return ResultSet.ok(iSysPostService.list());
    }

    /**
     * 新增岗位信息
     *
     * @param saveDTO 岗位信息
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermission('system:post:savePost')")
    @Operation(summary = "新增岗位信息")
    @Log(title = "岗位管理", businessType = BusinessType.INSERT)
    @PostMapping(value = "savePost")
    public ResultSet<String> savePost(@Validated @RequestBody SysPostSaveDTO saveDTO) {
        return ResultSet.ok(iSysPostService.savePost(saveDTO));
    }

    /**
     * 删除岗位
     *
     * @param postIds 岗位ID
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermission('system:post:removePost')")
    @Operation(summary = "删除岗位")
    @Log(title = "岗位管理", businessType = BusinessType.DELETE)
    @GetMapping(value = "removePost/{postIds}")
    public ResultSet<String> removePost(@PathVariable Long[] postIds) {
        return ResultSet.ok(iSysPostService.removePost(postIds));
    }

    /**
     * 修改岗位信息
     *
     * @param updateDTO 岗位信息
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermission('system:post:updatePost')")
    @Operation(summary = "修改岗位信息")
    @Log(title = "岗位管理", businessType = BusinessType.UPDATE)
    @PostMapping(value = "updatePost")
    public ResultSet<String> updatePost(@Validated @RequestBody SysPostUpdateDTO updateDTO) {
        return ResultSet.ok(iSysPostService.updatePost(updateDTO));
    }
}
